package de.fhhannover.inform.hnefatafl.spiel;

import de.fhhannover.inform.hnefatafl.vorgaben.Move;

public class Fassade extends Thread{
	
	private static Fassade instance = null;
	
	public Board  gamingBoard;
	
	
	private Fassade(){
		gamingBoard = new Board();
	}

	public static Fassade getInstance(){
		if(instance == null){
			instance = new Fassade();
		}
		return instance;
	}

	public void initialisiereSpiel(String attackerName, String defenderName, boolean isAttackerHuman, boolean isDefenderHuman, int kiDenkzeit, int attackerKI, int defenderKI) {
		gamingBoard.initialGame(attackerName, isAttackerHuman, defenderName, isDefenderHuman, kiDenkzeit, attackerKI, defenderKI);
		this.start();
	}


	public void makeMove(Move move){
		gamingBoard.makeMove(move);
	}

	@Override
	public void run() {
		while(gamingBoard.getIsGameRunning() == true){
			if(gamingBoard.getIsAttackerHuman() == false && gamingBoard.getIsAttackersTurn() == true){
				gamingBoard.makeMove(gamingBoard.attacker.calculateAttackerMove(gamingBoard.getLastMove(), gamingBoard.thinkingTime));
				try{
					sleep(gamingBoard.thinkingTime * 1000);
				}
				catch(InterruptedException e) {
		        }
			}
			if(gamingBoard.getIsDefenderHuman() == false && gamingBoard.getIsAttackersTurn() == false){
				gamingBoard.makeMove(gamingBoard.defender.calculateDefenderMove(gamingBoard.getLastMove(), gamingBoard.thinkingTime));
				try{
					sleep(gamingBoard.thinkingTime * 1000);
				}
				catch(InterruptedException e) {
		        }
			}
		}
	}
	
	

}
